﻿using FastReport;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Butcher.winform.EnterpriseForms.ReportForm.SalesSchedule;

namespace Butcher.winform.EnterpriseForms.ReportForm
{
    public partial class SalesSummarySheet : Form
    {
        public SalesSummarySheet()
        {
            InitializeComponent();
        }
        public string frx;
        private void SalesSummarySheet_Load(object sender, EventArgs e)
        {
            Report report = new Report();
            if (!string.IsNullOrWhiteSpace(frx))
                report.Load(frx);


            string url = @"http://localhost:5229/api/Ending/postSaleSummary";
            HttpClient client = new HttpClient();
            thisDATe approach = new thisDATe();
            var content = new StringContent(JsonSerializer.Serialize<thisDATe>(approach));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var results = info["date"].Value<JArray>();



          


            // 加载报表模板，这里假设模板文件是 "YourReportTemplate.frx"
            report.Load("../../../FastReport\\FastREport模版\\销售汇总表\\333.frx");
         
            DataSet ds = new DataSet();
            DataTable fr_dt = new DataTable();
            fr_dt.TableName = "baseInfos";
            fr_dt.Columns.Add("patName", typeof(String));//*****列名设置需要与标签模板一致*****
            fr_dt.Columns.Add("patset", typeof(String));
            fr_dt.Columns.Add("patone", typeof(String));
            fr_dt.Columns.Add("pattwo", typeof(String));
            fr_dt.Columns.Add("patthree", typeof(String));
            fr_dt.Columns.Add("patfour", typeof(String));
            fr_dt.Columns.Add("patfive", typeof(String));
            fr_dt.Columns.Add("patsix", typeof(String));
            fr_dt.Columns.Add("patsever", typeof(String));
            fr_dt.Columns.Add("pateight", typeof(String));
            fr_dt.Columns.Add("patnine", typeof(String));
            fr_dt.Columns.Add("patten", typeof(String));
            for (int i = 0; i < results.Count; i++)
            {
                fr_dt.Rows.Add(results[i]["clientID"], results[i]["weightNum"], results[i]["netWeight"]);

            }
            ds.Tables.Add(fr_dt);
            report.RegisterData(ds);//将数据传递至标签模板

            designerControl1.Report = report;
            //restore the design layout. Without this code, the designer tool windows will be unavailable
            designerControl1.RefreshLayout();
        }
    }
}
